<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<link rel="stylesheet" href="/static/css/metro-all.min.css">
	<link rel="stylesheet" href="/static/css/schemes/darcula.min.css">
</head>
<body class="bg-dack m-0 p-2">
	<!--  -->
	<header class="grid">
		<div class="row mt-10">
			<div class="cell-12"><h4>用户列表</h4></div>
		</div>
	</header>
	<!--  -->
	<section>
		<article class="grid m-0 p-0">
		<div class="row">
			<div class="cell-12">
				<table class="table striped row-hover cell-hover table-border row-border">
					<thead >
						<tr>
							<th class="text-center">用户</th>
							<th class="text-center">身份</th>
							<th class="text-center">查看</th>
						</tr>
					</thead>
					<tbody id="tabledata" class="text-center"></tbody>
					<tfoot>
						<th class="text-center"></th>
						<th class="text-center"></th>
						<th class="text-center"><button class="button info">添加</button></th>
					</tfoot>
				</table>
			</div>
		</div>
		<div id='page'></div>
		</article>
	</section>
	<!--  -->
	<footer class="grid text-center">
		
	</footer>
</body>
<foot>
	<script src="/static/js/jquery-3.3.1.min.js"></script>
	<script src="/static/js/metro.js"></script>
	<script>

	function tableDataProcessing(res)
	{
		str = '';
		for (var i = 0; i < res.length; i++)
		{
			str += 
			'<tr>'+
				'<td>'+res[i].username+'</td>'+
				'<td>'+res[i].group_id+'</td>'+
				'<td><button class="button" onclick="getDetails('+res[i].id+')">查看</button></td>'+
			'</tr>';
		}
		return str;
	}

	function pagelist(page=0)
	{
		var url = 'http://192.168.0.101/admin/admin_user/listUser.html';
		$.post(url,{page:page},function(res)
		{
			if (0 == res.code)
			{
				data = tableDataProcessing(res.data.data);
				$("#tabledata").html(data);
				$("#page").html('');
				$("#page").html(res.data.page);
			} else {
				$("#tabledata").html('<tr><td class="text-center" colspan="10"><h5>暂时没有数据，请前往添加</h5></td></tr>');
			}
		});
	}
	pagelist();

	function getDetails(id)
	{
		var url = 'http://192.168.0.101/admin/admin_user/getUser.html';
		$.post(url,{id:id},function(res)
		{
			if (0 === res.code)
			{
				Metro.toast.create('请稍后', function(){
					Metro.storage.setItem('user_detauls', res.data);
					window.location.href = 'http://192.168.0.101/admin/admin_user/edit';
				},1000); 
			}
			else { Metro.toast.create(res.msg, null, 3000); }
		});
	}
</script>
</foot>
</html>

